-- GuiRenderer
-- Gui渲染器

GuiRenderer = class()

function GuiRenderer:init()
    spriteMode(CORNER)
    debugInfo = DebugInfo()
    self.visible = true
    self.pauseButton = ImageButton(WIDTH - 30,HEIGHT - 25,"Project:PauseButton")
    self.width = 50
    self.pauseButton.color = color(255, 255, 255, 129)
    self.pauseButton.pressedColor = color(127, 127, 127, 209)
    self.pauseButton.clicked = function()
        control:resetAllTouch()
        timer:pause()
        self.visible = false
        GameState = Pause
    end
end

function GuiRenderer:render()
    ortho(0, WIDTH, 0, HEIGHT,-1000,1000)
    viewMatrix(matrix())
    translate(0,0,500)
    
    if self.visible == false or GameSetting.HideGui == true then return end
    
    spriteMode(CORNER)
    debugInfo:draw()
    control:draw()
    selector:render()
    healthBar:render()
    -- oxygenBar:render()
    self:drawCrosshair()
    self.pauseButton:draw()
end

function GuiRenderer:touched(touch)
    if self.pauseButton:touched(touch) then
        return true
    elseif control:touched(touch) then
        return true
    elseif selector:touched(touch) then
        return true
    end
end

-- 画准星
function GuiRenderer:drawCrosshair()
    local cx,cy = WIDTH / 2,HEIGHT / 2
    local l = 15
    stroke(255, 255, 255, 121)
    strokeWidth(4)
    line(cx,cy - l,cx,cy + l)
    line(cx - l,cy,cx + l,cy)
end
